home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / CChessPieces ƒ / CRook.cp < prev    next >
Text File  |  1993-05-26  |  2KB  |  80 lines

  1. ////////////
  2. //
  3. //    CRook.cp
  4. //
  5. //    Chess Piece methods for implementing a Rook.
  6. //
  7. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  8. //
  9. ////////////
  10.  
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include "CChessBoard.h"
  15. #include "CChessPiece.h"
  16. #include "CRook.h"
  17.  
  18. extern    CIconHandle    gWhiteRookCicnHandle;
  19. extern    CIconHandle    gBlackRookCicnHandle;
  20.  
  21. void CRook::IRook(Boolean aColor)
  22. {
  23.     inherited::IChessPiece(aColor);
  24.     itsValue = 0x0500;
  25.     canCastle = true;
  26. }
  27.  
  28. void CRook::Draw(short rank, short file)
  29. {
  30.     CIconHandle cicnHandle;
  31.     Rect aRect;
  32.     short rankQD = (rank - 1) << 5, fileQD = (file - 1) << 5;
  33.     
  34.     if (itsColor == White)
  35.         cicnHandle = gWhiteRookCicnHandle;
  36.     else
  37.         cicnHandle = gBlackRookCicnHandle;
  38.  
  39.     aRect.left = rankQD;
  40.     aRect.right = rankQD+32;
  41.     aRect.top = fileQD;
  42.     aRect.bottom = fileQD+32;
  43.     PlotCIcon(&aRect,cicnHandle);
  44. }
  45.  
  46. CIconHandle    CRook::GetCicnHandle(void)
  47. {
  48.     return gWhiteRookCicnHandle;
  49. }
  50.  
  51. Boolean    CRook::IsValidMove(CChessBoard *aBoard, short newRank, short newFile)
  52. {
  53.     short    oldRank = aBoard->firstClickRank, oldFile = aBoard->firstClickFile;
  54.     register i;
  55.     short iDelta;
  56.     
  57.     if (oldRank == newRank)
  58.     {
  59.         iDelta = abs(newFile-oldFile)/(newFile-oldFile);
  60.         for (i=oldFile+iDelta;i!=newFile;i+=iDelta)
  61.             if (aBoard->theBoard[oldRank][i])
  62.                 return false;
  63.         return true;
  64.     }
  65.     if (oldFile == newFile)
  66.     {
  67.         iDelta = abs(newRank-oldRank)/(newRank-oldRank);
  68.         for (i=oldRank+iDelta;i!=newRank;i+=iDelta)
  69.             if (aBoard->theBoard[i][oldFile])
  70.                 return false;
  71.         return true;
  72.     }
  73.     return false;    
  74. }
  75.  
  76. void CRook::RegisterMove(short rank, short file)
  77. {
  78.     canCastle = false;
  79.     inherited::RegisterMove(rank,file);
  80. }